//
//  TicketView.m
//  项目三
//
//  Created by rimi on 15/10/9.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "TicketView.h"

@interface TicketView() {

    UILabel *_time;
    UILabel *_place;
    UILabel *_behave;
    UILabel *_money;
    UILabel *_state;
    UILabel *_score;
}

@property (nonatomic, strong) UIImageView *backgroundImage;

@property (nonatomic, strong) UIButton *photoBtn;
@property (nonatomic, strong) UIButton *searchBtn;
@property (nonatomic, strong) UIButton *payBtn;
@property (nonatomic, strong) UIButton *cancelBtn;
@property (nonatomic, strong) UIImageView *textfieldView;
@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) UIImageView *word;


- (void)initializeAppearence;
@end

@implementation TicketView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeAppearence];
    }
    return self;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self initializeAppearence];
    }
    return self;
}

- (void)initializeAppearence {

    [self addSubview:self.backgroundImage];
    [self addSubview:self.photoBtn];
    [self addSubview:self.searchBtn];
    [self addSubview:self.payBtn];
    [self addSubview:self.cancelBtn];
    [self addSubview:self.textfieldView];
    [self addSubview:self.textField];
    [self addSubview:self.word];
    
    for (int i = 0; i < 6; i++) {
        UILabel *label = [[UILabel alloc] initWithFrame:DHFlexibleFrame(CGRectMake(300, 218 + i * (32 + 7), 360, 32))];
        label.tag = 100 + i;
        [self addSubview:label];
    }
    
    _time = (UILabel *)[self viewWithTag:100];
    _place = (UILabel *)[self viewWithTag:101];
    _behave = (UILabel *)[self viewWithTag:102];
    _money = (UILabel *)[self viewWithTag:103];
    _state = (UILabel *)[self viewWithTag:104];
    _score = (UILabel *)[self viewWithTag:105];
}
#pragma mark - action on button
- (void)actionOnPhotoBtn {
    
    
}
- (void)actionOnSearchBtn {
    
    
}
- (void)actionOnPayBtn {
    
    
}
- (void)actionOnCancelBtn {
    
    [UIView animateWithDuration:1.0 animations:^{
        self.alpha = 0;
    }];
    [self removeFromSuperview];
}
#pragma mark - getter
- (UIImageView *)backgroundImage {
    
    if (!_backgroundImage) {
        _backgroundImage = ({
            
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
            imageView.image = [UIImage imageNamed:@"灰色背景"];
            
            imageView;
        });
    }
    return _backgroundImage;
}
- (UIButton *)photoBtn {
    
    if (!_photoBtn) {
        _photoBtn = ({
            
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(140, 109, 125, 55))];
            [button setImage:[UIImage imageNamed:@"拍码-1"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnPhotoBtn) forControlEvents:UIControlEventTouchUpInside];
            
            button;
        });
    }
    return _photoBtn;
}
- (UIButton *)cancelBtn {
    
    if (!_cancelBtn) {
        _cancelBtn = ({
            
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(380, 476, 150, 50))];
            [button setImage:[UIImage imageNamed:@"缴费取消"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnCancelBtn) forControlEvents:UIControlEventTouchUpInside];
            
            button;
            
        });
    }
    return _cancelBtn;
}
- (UIButton *)payBtn {
    
    if (!_payBtn) {
        _payBtn = ({
            
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(179, 476, 150, 50))];
            [button setImage:[UIImage imageNamed:@"缴付罚款"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnPayBtn) forControlEvents:UIControlEventTouchUpInside];
            
            button;
            
        });
    }
    return _payBtn;
}
- (UIButton *)searchBtn {
    
    if (!_searchBtn) {
        _searchBtn = ({
            
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(574, 115, 84, 30))];
            [button setImage:[UIImage imageNamed:@"条码查询"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnSearchBtn) forControlEvents:UIControlEventTouchUpInside];
            
            button;
            
        });
    }
    return _searchBtn;
}
- (UIImageView *)textfieldView {

    if (!_textfieldView) {
        _textfieldView = ({
        
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(288, 120, 260, 34))];
            imageView.image = [UIImage imageNamed:@"自定义输入框"];
            imageView;
        });
    }
    return _textfieldView;
}
- (UITextField *)textField {

    if (!_textField) {
        _textField = ({
        
            UITextField *textfield = [[UITextField alloc] initWithFrame:DHFlexibleFrame(CGRectMake(295, 125, 245, 27))];
            
            textfield;
        });
    }
    return _textField;
}
- (UIImageView *)word {

    if (!_word) {
        _word = ({
        
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(160, 215, 96, 234))];
            imageView.image = [UIImage imageNamed:@"字_05"];
            imageView;

        });
    }
    return _word;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [self endEditing:YES];
}
@end
